<?php

class Get_profile_infos extends CI_Model {

    
    function getInfos($username) {
        $this->mongo_db->where('username', $username);
        $query = $this->mongo_db->get('community');
        if (!empty($query)) {
            
                    $data = array(
                        "user_id"       => $query[0]["user_id"],
                        "first_name"    => $query[0]["first_name"],
                        "last_name"     => $query[0]["last_name"],
                        "username"      => $query[0]["username"],
                        "email_address" => $query[0]["email_address"],
                        "profile_pic" => $query[0]["profile_pic"],
                        "profile_pic_thumb" => $query[0]["profile_pic_thumb"],
                        "about"       => $query[0]["about"],
                        "skype" => $query[0]["skype"],
                        "birthday_day" => $query[0]["birthday_day"],
                        "birthday_month" => $query[0]["birthday_month"],
                        "birthday_year" => $query[0]["birthday_year"],
                        "city" => $query[0]["city"],
                        "tracer" => $query[0]["tracer"],
                        "shoe" => $query[0]["shoe"],
                        "spot" => $query[0]["spot"],
                        "profile_cover" => $query[0]["profile_cover"],
                        "profile_cover_pos" => $query[0]["profile_cover_pos"],
                        "mood" => $query[0]["mood"],
                    );
                    return $data;
        }
    }
    function getInfosID($user_id) {
        $this->mongo_db->where('user_id', (string)$user_id);
        $query = $this->mongo_db->get('community');
        if (!empty($query)) {
                    $this->mongo_db->where(array('user_id_to' => (string)$user_id,'status' => 'new'));
                    $notification = $this->mongo_db->get('notifications');
//                    $data = array(
//                        "user_id"       => $query[0]["user_id"],
//                        "first_name"    => $query[0]["first_name"],
//                        "last_name"     => $query[0]["last_name"],
//                        "username"      => $query[0]["username"],
//                        "email_address" => $query[0]["email_address"],
//                        "profile_pic" => $query[0]["profile_pic"],
//                        "about" => $query[0]["about"],
//                        "profile_pic_thumb" => $query[0]["profile_pic_thumb"],
//                        "skype" => $query[0]["skype"],
//                        "birthday_day" => $query[0]["birthday_day"],
//                        "birthday_month" => $query[0]["birthday_month"],
//                        "birthday_year" => $query[0]["birthday_year"],
//                        "city" => $query[0]["city"],
//                        "tracer" => $query[0]["tracer"],
//                        "shoe" => $query[0]["shoe"],
//                        "spot" => $query[0]["spot"],
//                        "profile_cover" => $query[0]["profile_cover"],
//                        "profile_cover_pos" => $query[0]["profile_cover_pos"],
//                        "notification" => $notification
//                    );
        $query[0]['notification'] = $notification;
        return $query[0];
        }
    }
    function getUsername($user_id) {

        $this->mongo_db->where('user_id', (string)$user_id);
        $query = $this->mongo_db->get('community');
        if (!empty($query)) {
                    return $query[0]["username"];
        }
    }
    function getUsername_id($user_id) {

        $this->mongo_db->where('_id', new MongoId($user_id));
        $query = $this->mongo_db->get('community');
        if (!empty($query)) {
                    return $query[0]["username"];
        }
    }
    function getname($user_id) {

        $this->mongo_db->where('user_id', (string)$user_id);
        $query = $this->mongo_db->get('community');
        if (!empty($query)) {
                    return $query[0]["first_name"]." ".$query[0]["last_name"];
        }
    }
    function checkIfExists($username){
        $this->mongo_db->where('username', $username);
        $query = $this->mongo_db->get('community');
        if (!empty($query)) {
            return true;
        }
    }
    function getUsers(){
        $query = $this->mongo_db->get('community');
        return $query;
    }
    function getUsersSearch(){
        $this->mongo_db->like('first_name', $this->input->get('name'), '.', FALSE, TRUE);
        $query1 = $this->mongo_db->get('community');
        
        $this->mongo_db->like('last_name', $this->input->get('name'), '.', FALSE, TRUE);
        $query2 = $this->mongo_db->get('community');
                
        foreach($query2 as $key => $value){
            array_push($query1, $value);
        }
        
        return $query1;
    }
    function getProfilePicture($user_id){
        $this->mongo_db->where('user_id', (string)$user_id);
        $query = $this->mongo_db->get('community');
        return $query[0]["profile_pic_thumb"];
        
    }
    function editMood($mood){
        $data = array(
                        "mood"       => $mood,
                    );
        $this->mongo_db->where('user_id' , $this->input->cookie('LEAPSESSID'));
        $query = $this->mongo_db->set($data)->update('community');
        return $query;
    }
}